package com.example.ecs.components.render;

import com.example.ecs.core.ComponentKey;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;

/**
 * PolygonRenderComponent类表示多边形渲染组件
 */
@ComponentKey(RenderableComponent.class)
public class PolygonRenderComponent extends RenderableComponent {
    public double[][] vertices;
    
    public PolygonRenderComponent(Color color, double[][] vertices) {
        super(color);
        this.vertices = vertices;
    }
    
    @Override
    public void render(Graphics2D g, double x, double y) {
        g.setColor(color);
        
        // 创建多边形
        Polygon polygon = new Polygon();
        for (double[] vertex : vertices) {
            polygon.addPoint((int)(x + vertex[0]), (int)(y + vertex[1]));
        }
        
        g.fillPolygon(polygon);
    }
}